using System;
using System.Collections.Generic;
using System.IO;
using CKS.EBE.API;
using CKS.EBE.Logging;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint;
using System.Web.UI.WebControls;

namespace CKS.EBE
{
    public class SettingsPage : LayoutsPageBase
    {
        protected InputFormControl idSettingsControlExtensionsEnabled;
        protected InputFormControl idSettingsControlCachinEnabled;
        //protected InputFormControl idSettingsControlCachingListItemsEnabled;
        protected InputFormControl idSettingsControlPostTrimmingEnabled;
        protected InputFormControl idSettingsControlAkismetKey;
        protected InputFormControl idSettingsControlDeleteSpamComments;
        protected InputFormControl idSettingsControlEnableCaptchaComments;
        protected InputFormControl idSettingsControlBlogThemeList;
        protected InputFormControl idSettingsControlCustomRSSFeed;
        protected InputFormControl idSettingsControlThemeSelectorEnabled;
        protected InputFormControl idSettingsControlRedirectPostAspx;
        protected InputFormControl idSettingsControlContactEmail;
        protected InputFormControl idSettingsControlPingbacksEnabled;
        protected InputFormControl idSettingsControlTrackbackReceiptEnabled;
        protected InputFormControl idSettingsControlDisableSelfTrackbacks;
        protected InputFormControl idSettingsControlMtfEnabled;
        protected InputFormControl idSettingsControlDisableConvertClientDates;
        protected InputFormControl idSettingsControlProxyPort;
        protected InputFormControl idSettingsControlProxyUrl;
        protected InputFormControl idSettingsControlSecureSystemPages;
        protected InputFormControl idSettingsControlRssItemCount;
        protected InputFormControl idSettingsControlRssPostTrimmingEnabled;
        protected InputFormControl idSettingsControlTransformParameters;
        protected InputFormControl idSettingsControlAutoApproveSpamFreeComments;

        protected InputFormControl idSettingsControlUseSiteCollectionThemes;
        protected InputFormControl idSettingsControlThemeWikiPages;
        protected InputFormControl idSettingsControlTechnoratiLinks;
        protected InputFormControl idSettingsControlPDFExport;

        protected InputFormCheckBox idCachinEnabled;
        //protected InputFormCheckBox idListItemCachingEnabled;
        protected InputFormCheckBox idThemeWikiPages;
        protected InputFormCheckBox idUseSiteCollectionThemes;
        protected InputFormCheckBox idPostTrimmingEnabled;
        protected InputFormTextBox idAkismetKey;
        protected InputFormCheckBox idDeleteSpamComments;
        protected InputFormCheckBox idEnableCaptchaComments;
        protected InputFormTextBox idBlogTheme;
        protected DropDownList idBlogThemeList;
        protected InputFormTextBox idCustomRSSFeed;
        protected InputFormCheckBox idThemeSelectorEnabled;
        protected InputFormCheckBox idRedirectPostAspx;
        protected InputFormTextBox idContactEmail;

        protected InputFormCheckBox idPingbacksEnabled;
        protected InputFormCheckBox idTrackbackReceiptEnabled;
        protected InputFormCheckBox idDisableSelfTrackbacks;
        protected InputFormCheckBox idMtfEnabled;
        protected InputFormCheckBox idTechnoratiLinks;
        protected InputFormTextBox idPDFExportLicenseKey;

        protected InputFormTextBox idPageCacheVaryByParam;
        protected InputFormTextBox idPageCacheTimeout;

        protected InputFormCheckBox idExtensionsEnabled;
        protected InputFormCheckBox idAutoApproveComments;
        protected InputFormCheckBox idEnhancedXslCahingDisabled;
        
        protected InputFormCheckBox idDisableConvertClientDates;
        protected InputFormCheckBox idRssPostTrimmingEnabled;
        protected InputFormTextBox idProxyPort;
        protected InputFormTextBox idProxyUrl;
        protected InputFormTextBox idRssItemCount;

        protected InputFormCheckBox idSecureSystemPages;
        protected InputFormTextBox idTransformParameter1;
        protected InputFormTextBox idTransformParameter2;
        protected InputFormTextBox idTransformParameter3;
        protected InputFormSection idDebugSection;

		  protected RadioButtonList LoggingLevel;

        protected Button ButRestoreThemes;
        protected Button BtnApply;

        protected Literal litPageTitle;
        protected Literal litPageTitle2;
        protected Literal litCachingTitle;
        protected Literal litCachingDescription;
        protected Literal litCaptchaTitle;
        protected Literal litCaptchaDescription;
        protected Literal litClientDateTimeConversionTitle;
        protected Literal litClientDateTimeConversionDescription;
        protected Literal litContactEmailTitle;
        protected Literal litContactEmailDescription;
        protected Literal litPostTrimmingTitle;
        protected Literal litPostTrimmingDescription;
        protected Literal litSecureSystemPagesTitle;
        protected Literal litSecureSystemPagesDescription;
        protected Literal litCustomTransformParametersTitle;
        protected Literal litCustomTransformParametersDescription;
        protected Literal litAkismetKeyTitle;
        protected Literal litAkismetKeyDescription;
        protected Literal litAutoRecycleSpamCommentsTitle;
        protected Literal litAutoRecycleSpamCommentsDescription;
        protected Literal litAutoApproveSpamFreeCommentsTitle;
        protected Literal litAutoApproveSpamFreeCommentsDescription;
        protected Literal litAutoTrackbackTitle;
        protected Literal litAutoTrackbackDescription;
        protected Literal litReceiveTrackbacksTitle;
        protected Literal litReceiveTrackbacksDescription;
        protected Literal litProxyUrlTitle;
        protected Literal litProxyUrlDescription;
        protected Literal litProxyPortTitle;
        protected Literal litProxyPortDescription;
        protected Literal litDefaultBlogThemeTitle;
        protected Literal litDefaultBlogThemeDescription;
        protected Literal litShowThemeTitle;
        protected Literal litShowThemeDescription;
        protected Literal litCustomRSSFeedTitle;
        protected Literal litCustomRSSFeedDescription;
        protected Literal litRedirectPostPageTitle;
        protected Literal litRedirectPostPageDescription;
        protected Literal litEnableMTFTitle;
        protected Literal litEnableMTFDescription;
        protected Literal litRSSFeedItemCountTitle;
        protected Literal litRSSFeedItemCountDescription;

        protected Literal litThemeWikiPagesTitle;
        protected Literal litUseSiteCollectionThemesTitle;
        protected Literal litThemeWikiPagesDescription;
        protected Literal litUseSiteCollectionThemesDescription;
        protected Literal litTechnoratiLinksTitle;
        protected Literal litTechnoratiLinksDescription;
        protected Literal litPDFExportTitle;
        protected Literal litPDFExportDescription;
        protected Label ErrorLabel;
        
        protected override void OnLoad(EventArgs e)
        {
            try
            {
                EnsureChildControls();

                if (Page.Request["debug"] == "true")
                {
                    idDebugSection.Visible = true;
                    ButRestoreThemes.Attributes.Add("onclick", "javascript:if(confirm('Are you sure you want to overwrite the themes?')== false) return false;");
                }

                if (!IsPostBack)
                {
                    BlogSettings settings = BlogContext.Current.Settings;
                    idPostTrimmingEnabled.Checked = settings.TrimPostBodyOnLists;
                    idAkismetKey.Text = settings.AkismetKey;
                    idDeleteSpamComments.Checked = settings.DeleteSpamComments;
                    idEnableCaptchaComments.Checked = settings.EnableCaptchaComments;
                    idCachinEnabled.Checked = settings.CachingEnabled;
                    //idListItemCachingEnabledidListItemCachingEnabled.Checked = settings.CacheListItemData;
                    idSecureSystemPages.Checked = settings.SecureSystemPages;
                    idThemeSelectorEnabled.Checked = settings.ThemeSelectorEnabled;
                    idRedirectPostAspx.Checked = settings.RedirectPostAspx;
                    idContactEmail.Text = settings.ContactEmail;

                    idExtensionsEnabled.Checked = settings.BlogExtensionsEnabled;
                    idPingbacksEnabled.Checked = settings.PingbacksEnabled;
                    idTrackbackReceiptEnabled.Checked = settings.TrackbackReceiptEnabled;
                    idDisableSelfTrackbacks.Checked = settings.DisableSelfTrackbacks;
                    idMtfEnabled.Checked = settings.MtfEnabled;

                    idProxyPort.Text = settings.ProxyPort;
                    idProxyUrl.Text = settings.ProxyUrl;
                    idRssPostTrimmingEnabled.Checked = settings.TrimPostBodyOnRss;
                    idDisableConvertClientDates.Checked = settings.DisableConvertClientDates;
                                
                    idTransformParameter1.Text = settings.BlogTransformParameter1;
                    idTransformParameter2.Text = settings.BlogTransformParameter2;
                    idTransformParameter3.Text = settings.BlogTransformParameter3;

                    idCustomRSSFeed.Text = settings.CustomRSSFeedUrl;

                    idPDFExportLicenseKey.Text = settings.PDFExportLicenseKey;

                    if (idAutoApproveComments != null)
                        idAutoApproveComments.Checked = settings.AutoApproveComments;

                    if (idRssItemCount != null)
                        idRssItemCount.Text = settings.RssItemCount;

                    if (idPageCacheTimeout != null)
                        idPageCacheTimeout.Text = settings.PageOutputCacheTimeout.ToString();

                    if (idPageCacheVaryByParam != null)
                        idPageCacheVaryByParam.Text = settings.PageOutputCacheVaryByParam;

                    List<string> availableThemes = Themes.GetThemes(SPContext.Current.Web);
                    idBlogThemeList.DataSource = availableThemes;
                    idBlogThemeList.DataBind();
                    idBlogThemeList.Items.Insert(0, "");

                    if (!string.IsNullOrEmpty(settings.BlogTheme)) idBlogThemeList.SelectedValue = settings.BlogTheme;

                    LocalizeControls();

                    try
                    {
                        idThemeWikiPages.Checked = settings.ThemeWikiPages;
                        idUseSiteCollectionThemes.Checked = settings.UseSiteCollectionThemes;
                        idTechnoratiLinks.Checked = settings.TechnoratiLinks;
                        idEnhancedXslCahingDisabled.Checked = settings.XslCacheDependencyDisabled;
                    		LoggingLevel level = (LoggingLevel)settings.LoggingLevel;
                    		LoggingLevel.SelectedIndex = (int)level;
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Trace.WriteLine(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorLabel.Text += string.Format("Error in OnLoad: {0}", ex);
            }

            base.OnLoad(e);
        }

        protected override bool RequireSiteAdministrator
        {
            get
            {
                return false;
            }
        }

        protected override SPBasePermissions RightsRequired
        {
            get
            {
                return SPBasePermissions.ManageWeb;
            }
        }

        protected void UpdateAllPosts(object target, EventArgs e)
        {
            SPList oPosts = Helper.GetListByFolderName(Web, Localization.GetListName(Localization.BlogList.Posts, Web.Language));
            foreach (SPListItem oPost in oPosts.Items)
            {
                oPost.SystemUpdate();
            }
        }

        /// <summary>
        /// overwrite all themes with the themes from the features folder
        /// </summary>
        /// <param name="target"></param>
        /// <param name="e"></param>
        protected void RestoreThemes(object target, EventArgs e)
        {
            try
            {
                SPWeb web = SPContext.Current.Web;
                SPFolder themesFolder = web.RootFolder.SubFolders["themes"];
                SPFeature themesFeature = web.Features[BlogContext.BlogThemeFeatureGUID];
                string[] arThemes = Directory.GetDirectories(themesFeature.Definition.RootDirectory + "\\Themes");

                foreach (string sTheme in arThemes)
                {
                    string[] arMasterPages = Directory.GetFiles(sTheme, "*.master");
                    foreach (string sFile in arMasterPages)
                    {
                        FileInfo file = new FileInfo(sFile);

                        if (file.Exists && file.Directory != null)
                        {
                            SPFolder oThemeFolder;
                            try
                            {
                                oThemeFolder = themesFolder.SubFolders[file.Directory.Name];
                            }
                            catch
                            {
                                oThemeFolder = themesFolder.SubFolders.Add(file.Directory.Name);
                            }

                            using (Stream oStream = File.OpenRead(file.FullName))
                            {
                                oThemeFolder.Files.Add(file.Name, oStream, true);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new SPException(ex.Message, ex);
            }
        }

        protected void ApplySettings(object target, EventArgs e)
        {
            try
            {
                BlogSettings settings = BlogContext.Current.Settings;

                if (idAutoApproveComments != null)
                    settings.AutoApproveComments = idAutoApproveComments.Checked;

                if (idRssItemCount != null)
                    settings.RssItemCount = idRssItemCount.Text;

                settings.AkismetKey = idAkismetKey.Text;
                settings.BlogTheme = idBlogThemeList.SelectedValue; //idBlogTheme.Text;
                settings.CachingEnabled = idCachinEnabled.Checked;
                //settings.CacheListItemData = idListItemCachingEnabled.Checked;
                settings.DeleteSpamComments = idDeleteSpamComments.Checked;
                settings.EnableCaptchaComments = idEnableCaptchaComments.Checked;
                settings.TrimPostBodyOnLists = idPostTrimmingEnabled.Checked;
                settings.SecureSystemPages = idSecureSystemPages.Checked;
                settings.ThemeSelectorEnabled = idThemeSelectorEnabled.Checked;
                settings.RedirectPostAspx = idRedirectPostAspx.Checked;
                settings.ContactEmail = idContactEmail.Text;

                settings.BlogExtensionsEnabled = idExtensionsEnabled.Checked;
                settings.PingbacksEnabled = idPingbacksEnabled.Checked;
                settings.TrackbackReceiptEnabled = idTrackbackReceiptEnabled.Checked;
                settings.DisableSelfTrackbacks = idDisableSelfTrackbacks.Checked;

                settings.MtfEnabled = idMtfEnabled.Checked;

                settings.ProxyPort = idProxyPort.Text;
                settings.ProxyUrl = idProxyUrl.Text;
                settings.TrimPostBodyOnRss = idRssPostTrimmingEnabled.Checked;
                settings.DisableConvertClientDates = idDisableConvertClientDates.Checked;

                settings.BlogTransformParameter1 = idTransformParameter1.Text;
                settings.BlogTransformParameter2 = idTransformParameter2.Text;
                settings.BlogTransformParameter3 = idTransformParameter3.Text;

                settings.CustomRSSFeedUrl = idCustomRSSFeed.Text;

                settings.PDFExportLicenseKey = idPDFExportLicenseKey.Text;

                if (idPageCacheTimeout != null)
                    settings.PageOutputCacheTimeout = int.Parse(idPageCacheTimeout.Text);

                if (idPageCacheVaryByParam != null)
                    settings.PageOutputCacheVaryByParam = idPageCacheVaryByParam.Text;

                try
                {
                    settings.ThemeWikiPages = idThemeWikiPages.Checked;
                    settings.UseSiteCollectionThemes = idUseSiteCollectionThemes.Checked;
                    settings.TechnoratiLinks = idTechnoratiLinks.Checked;
                    settings.XslCacheDependencyDisabled = idEnhancedXslCahingDisabled.Checked;
                	  settings.LoggingLevel = LoggingLevel.SelectedIndex;
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Trace.WriteLine(ex);
                }

                settings.Update();

                Response.Redirect(SPContext.Current.Web.Url + "/_layouts/settings.aspx");
            }
            catch (Exception ex)
            {
                ErrorLabel.Text += string.Format("Error in ApplySettings: {0}", ex);
            }
        }

        private void LocalizeControls()
        {
            try
            {
                litPageTitle.Text = Localization.GetResource("BlogSettings");
                litPageTitle2.Text = Localization.GetResource("BlogSettings");
                litCachingTitle.Text = Localization.GetResource("SettingsTitle_Caching");
                litCachingDescription.Text = Localization.GetResource("SettingsDescription_Caching");
                litCaptchaTitle.Text = Localization.GetResource("SettingsTitle_Captcha");
                litCaptchaDescription.Text = Localization.GetResource("SettingsDescription_Captcha");
                litClientDateTimeConversionTitle.Text = Localization.GetResource("SettingsTitle_ClientDateTimeConversion");
                litClientDateTimeConversionDescription.Text = Localization.GetResource("SettingsDescription_ClientDateTimeConversion");
                litContactEmailTitle.Text = Localization.GetResource("SettingsTitle_ContactEmail");
                litContactEmailDescription.Text = Localization.GetResource("SettingsDescription_ContactEmail");
                litPostTrimmingTitle.Text = Localization.GetResource("SettingsTitle_PostTrimming");
                litPostTrimmingDescription.Text = Localization.GetResource("SettingsDescription_PostTrimming");
                litSecureSystemPagesTitle.Text = Localization.GetResource("SettingsTitle_SecureSystemPages");
                litSecureSystemPagesDescription.Text = Localization.GetResource("SettingsDescription_SecureSystemPages");
                litCustomTransformParametersTitle.Text = Localization.GetResource("SettingsTitle_CustomTransformParameters");
                litCustomTransformParametersDescription.Text = Localization.GetResource("SettingsDescription_CustomTransformParameters");
                litAkismetKeyTitle.Text = Localization.GetResource("SettingsTitle_AkismetKey");
                litAkismetKeyDescription.Text = Localization.GetResource("SettingsDescription_AkismetKey");
                litAutoRecycleSpamCommentsTitle.Text = Localization.GetResource("SettingsTitle_AutoRecybleSpamComments");
                litAutoRecycleSpamCommentsDescription.Text = Localization.GetResource("SettingsDescription_AutoRecybleSpamComments");
                litAutoApproveSpamFreeCommentsTitle.Text = Localization.GetResource("SettingsTitle_AutoApproveSpamFreeComments");
                litAutoApproveSpamFreeCommentsDescription.Text = Localization.GetResource("SettingsDescription_AutoApproveSpamFreeComments");
                litAutoTrackbackTitle.Text = Localization.GetResource("SettingsTitle_AutoTrackbackPinging");
                litAutoTrackbackDescription.Text = Localization.GetResource("SettingsDescription_AutoTrackbackPinging");
                litReceiveTrackbacksTitle.Text = Localization.GetResource("SettingsTitle_ReceiveTrackbacks");
                litReceiveTrackbacksDescription.Text = Localization.GetResource("SettingsDescription_ReceiveTrackbacks");
                litProxyUrlTitle.Text = Localization.GetResource("SettingsTitle_ProxyUrl");
                litProxyUrlDescription.Text = Localization.GetResource("SettingsDescription_ProxyUrl");
                litProxyPortTitle.Text = Localization.GetResource("SettingsTitle_ProxyPort");
                litProxyPortDescription.Text = Localization.GetResource("SettingsDescription_ProxyPort");
                litDefaultBlogThemeTitle.Text = Localization.GetResource("SettingsTitle_DefaultTheme");
                litDefaultBlogThemeDescription.Text = Localization.GetResource("SettingsDescription_DefaultTheme");
                litShowThemeTitle.Text = Localization.GetResource("SettingsTitle_ShowThemeSelector");
                litShowThemeDescription.Text = Localization.GetResource("SettingsDescription_ShowThemeSelector");
                litCustomRSSFeedTitle.Text = Localization.GetResource("SettingsTitle_CustomRSSFeed");
                litCustomRSSFeedDescription.Text = Localization.GetResource("SettingsDescription_CustomRSSFeed");
                litRedirectPostPageTitle.Text = Localization.GetResource("SettingsTitle_RedirectPostPage");
                litRedirectPostPageDescription.Text = Localization.GetResource("SettingsDescription_RedirectPostPage");
                litEnableMTFTitle.Text = Localization.GetResource("SettingsTitle_EnableMTF");
                litEnableMTFDescription.Text = Localization.GetResource("SettingsDescription_EnableMTF");
                litRSSFeedItemCountTitle.Text = Localization.GetResource("SettingsTitle_RSSItemCount");
                litRSSFeedItemCountDescription.Text = Localization.GetResource("SettingsDescription_RSSItemCount");

                try
                {
                    litUseSiteCollectionThemesDescription.Text = Localization.GetResource("SettingsDescription_UseSiteCollectionThemes");
                    litThemeWikiPagesDescription.Text = Localization.GetResource("SettingsDescription_ThemeWikiPages");
                    litUseSiteCollectionThemesDescription.Text = Localization.GetResource("SettingsTitle_UseSiteCollectionThemes");
                    litThemeWikiPagesTitle.Text = Localization.GetResource("SettingsTitle_ThemeWikiPages");
                    litTechnoratiLinksTitle.Text = Localization.GetResource("SettingsTitle_TechnoratiLinks");
                    litTechnoratiLinksDescription.Text = Localization.GetResource("SettingsDescription_TechnoratiLinks");
                    litPDFExportTitle.Text = Localization.GetResource("SettingsTitle_PDFExport");
                    litPDFExportDescription.Text = Localization.GetResource("SettingsDescription_PDFExport");
                }
                catch (Exception ex) {}

                BtnApply.Text = Localization.GetResource("SettingsControls_BtnApply");

                idAkismetKey.Attributes.Add("Title", Localization.GetResource("SettingsControls_idAkismetKey"));
                idAutoApproveComments.Attributes.Add("Title", Localization.GetResource("SettingsControls_idAutoApproveComments"));
                idCachinEnabled.Attributes.Add("Title", Localization.GetResource("SettingsControls_idCachinEnabled"));
                //idListItemCachingEnabled.Attributes.Add("Title", Localization.GetResource("SettingsControls_idListItemCachingEnabled"));
                idContactEmail.Attributes.Add("Title", Localization.GetResource("SettingsControls_idContactEmail"));
                idCustomRSSFeed.Attributes.Add("Title", Localization.GetResource("SettingsControls_idCustomRSSFeed"));
                idDeleteSpamComments.Attributes.Add("Title", Localization.GetResource("SettingsControls_idDeleteSpamComments"));
                idDisableConvertClientDates.Attributes.Add("Title", Localization.GetResource("SettingsControls_idDisableConvertClientDates"));
                idEnableCaptchaComments.Attributes.Add("Title", Localization.GetResource("SettingsControls_idEnableCaptchaComments"));
                idExtensionsEnabled.Attributes.Add("Title", Localization.GetResource("SettingsControls_idExtensionsEnabled"));
                idMtfEnabled.Attributes.Add("Title", Localization.GetResource("SettingsControls_idPingbacksEnabled"));
                idPingbacksEnabled.Attributes.Add("Title", Localization.GetResource("SettingsControls_idExtensionsEnabled"));
                idPostTrimmingEnabled.Attributes.Add("Title", Localization.GetResource("SettingsControls_idPostTrimmingEnabled"));
                idProxyPort.Attributes.Add("Title", Localization.GetResource("SettingsControls_idProxyPort"));
                idProxyUrl.Attributes.Add("Title", Localization.GetResource("SettingsControls_idProxyUrl"));
                idRedirectPostAspx.Attributes.Add("Title", Localization.GetResource("SettingsControls_idRedirectPostAspx"));
                idRssItemCount.Attributes.Add("Title", Localization.GetResource("SettingsControls_idRssItemCount"));
                idRssPostTrimmingEnabled.Attributes.Add("Title", Localization.GetResource("SettingsControls_idRssPostTrimmingEnabled"));
                idSecureSystemPages.Attributes.Add("Title", Localization.GetResource("SettingsControls_idSecureSystemPages"));
                idThemeSelectorEnabled.Attributes.Add("Title", Localization.GetResource("SettingsControls_idThemeSelectorEnabled"));
                idTrackbackReceiptEnabled.Attributes.Add("Title", Localization.GetResource("SettingsControls_idTrackbackReceiptEnabled"));
                idDisableSelfTrackbacks.Attributes.Add("Title", Localization.GetResource("SettingsControl_idDisableSelfTrackbacks"));
                idTransformParameter1.Attributes.Add("Title", Localization.GetResource("SettingsControls_idTransformParameter1"));
                idTransformParameter2.Attributes.Add("Title", Localization.GetResource("SettingsControls_idTransformParameter2"));
                idTransformParameter3.Attributes.Add("Title", Localization.GetResource("SettingsControls_idTransformParameter3"));

                try
                {
                    idUseSiteCollectionThemes.Attributes.Add("Title", Localization.GetResource("SettingsControls_idUseSiteCollectionThemes"));
                    idThemeWikiPages.Attributes.Add("Title", Localization.GetResource("SettingsControls_idThemeWikiPages"));
                    idSettingsControlUseSiteCollectionThemes.LabelText = Localization.GetResource("SettingsControls_idSettingsControlUseSiteCollectionThemes");
                    idSettingsControlThemeWikiPages.LabelText = Localization.GetResource("SettingsControls_idSettingsControlThemeWikiPages");
                    idSettingsControlTechnoratiLinks.LabelText = Localization.GetResource("SettingsControls_idSettingsControlTechnoratiLinks");
                    idSettingsControlPDFExport.LabelText = Localization.GetResource("SettingsControls_idSettingsControlPDFExport");
                }
                catch (Exception ex)
                {
                }

                idSettingsControlExtensionsEnabled.LabelText = Localization.GetResource("SettingsControls_idSettingsControlExtensionsEnabled");
                idSettingsControlCachinEnabled.LabelText = Localization.GetResource("SettingsControls_idSettingsControlCachinEnabled");
                //idSettingsControlCachingListItemsEnabled.LabelText = Localization.GetResource("SettingsControls_idSettingsControlCachingListItemsEnabled");
                idSettingsControlPostTrimmingEnabled.LabelText = Localization.GetResource("SettingsControls_idSettingsControlPostTrimmingEnabled");
                idSettingsControlAkismetKey.LabelText = Localization.GetResource("SettingsControls_idSettingsControlAkismetKey");
                idSettingsControlDeleteSpamComments.LabelText = Localization.GetResource("SettingsControls_idSettingsControlDeleteSpamComments");
                idSettingsControlEnableCaptchaComments.LabelText = Localization.GetResource("SettingsControls_idSettingsControlEnableCaptchaComments");
                idSettingsControlBlogThemeList.LabelText = Localization.GetResource("SettingsControls_idSettingsControlBlogThemeList");
                idSettingsControlCustomRSSFeed.LabelText = Localization.GetResource("SettingsControls_idSettingsControlCustomRSSFeed");
                idSettingsControlThemeSelectorEnabled.LabelText = Localization.GetResource("SettingsControls_idSettingsControlThemeSelectorEnabled");
                idSettingsControlRedirectPostAspx.LabelText = Localization.GetResource("SettingsControls_idSettingsControlRedirectPostAspx");
                idSettingsControlContactEmail.LabelText = Localization.GetResource("SettingsControls_idSettingsControlContactEmail");
                idSettingsControlPingbacksEnabled.LabelText = Localization.GetResource("SettingsControls_idSettingsControlPingbacksEnabled");
                idSettingsControlTrackbackReceiptEnabled.LabelText = Localization.GetResource("SettingsControls_idSettingsControlTrackbackReceiptEnabled");
                idSettingsControlDisableSelfTrackbacks.LabelText = Localization.GetResource("SettingsControl_idDisableSelfTrackbacks");
                idSettingsControlMtfEnabled.LabelText = Localization.GetResource("SettingsControls_idSettingsControlMtfEnabled");
                idSettingsControlDisableConvertClientDates.LabelText = Localization.GetResource("SettingsControls_idSettingsControlDisableConvertClientDates");
                idSettingsControlProxyPort.LabelText = Localization.GetResource("SettingsControls_idSettingsControlProxyPort");
                idSettingsControlProxyUrl.LabelText = Localization.GetResource("SettingsControls_idSettingsControlProxyUrl");
                idSettingsControlSecureSystemPages.LabelText = Localization.GetResource("SettingsControls_idSettingsControlSecureSystemPages");
                idSettingsControlAutoApproveSpamFreeComments.LabelText = Localization.GetResource("SettingsControls_idSettingsControlAutoApproveSpamFreeComments");
                idSettingsControlRssItemCount.LabelText = Localization.GetResource("SettingsControls_idSettingsControlRssItemCount");
                idSettingsControlRssPostTrimmingEnabled.LabelText = Localization.GetResource("SettingsControls_idSettingsControlRssPostTrimmingEnabled");
                idSettingsControlTransformParameters.LabelText = Localization.GetResource("SettingsControls_idSettingsControlTransformParameters");
            }
            catch (Exception ex)
            {
                ErrorLabel.Text += string.Format("Error in LocalizeControls: {0}", ex);
            }
        }
    }
}